import numpy as np
from math import pi, exp

sqrt_pi = (2 * pi) ** 0.5

class NBFunctions(object):

    @staticmethod
    def gaussian(x, mu, sigma):
        return exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (sqrt_pi * sigma)


    @staticmethod
    def gaussian_maximum_likelihood(labelled_x, n_category, dim):
        mu = [np.sum(labelled_x[c][dim]) /
              len(labelled_x[c][dim]) for c in range(n_category)]
        sigma = [np.sum((labelled_x[c][dim]-mu[c])**2 /
                len(labelled_x[c][dim]) for c in range(n_category))]

        def func(_c):
            def sub(xx):
                return NBFunctions.gaussian(xx, mu[_c], sigma[_c])
            return sub

        return [func(_c=c) for c in range(n_category)]